pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // TODO: 这里写逻辑
    if let Some(index) = num_str.find('('){
        let number: i32 = num_str[..index].parse().unwrap();
        let from_base: u32 = num_str[index+1..num_str.len()-1].parse().unwrap();
        let number_ten: i32 = x_to_ten(number, from_base);
        // println!("{}", number_ten);
        let number_to_base: String = ten_to_x(number_ten, to_base);
        // println!("{}", number_to_base);
        return number_to_base;
    }else {
        println!("Input Error")
    }
    todo!()
}

fn x_to_ten(num: i32, base: u32) -> i32{
    let mut is_negative = false;
    let mut  number:String = num.to_string();
    if num == 0 {
        return 0;
    }else if num < 0 {
        is_negative = true;
        number.remove(0);
    }
    let mut result: u32 = 0;
    let mut multi: u32 = 1;
    for c in number.chars().rev(){
        let now_num: u32 = c.to_digit(10).unwrap();
        result += multi * now_num;
        multi *= base;
    }
    return if !is_negative {result as i32} else {-(result as i32)};
}

fn ten_to_x(mut num: i32, base: u32) -> String{
    if num == 0 {
        return "0".to_string();
    }else if num < 0 {
        num = -num;
    }
    
    let mut result = String::new();
    while num != 0 {
        let yu = num % base as i32;
        if yu < 10 {
            result.insert_str(0, &yu.to_string());
        }else {
            match yu {
                10 => {result.insert(0, 'a');},
                11 => {result.insert(0, 'b');},
                12 => {result.insert(0, 'c');},
                13 => {result.insert(0, 'd');},
                14 => {result.insert(0, 'e');},
                15 => {result.insert(0, 'f');},
                _=>{}
            }
        }
        num = num / base as i32;
    }
    return result;
}
